package com.lzq.course.business.controller.web;

import com.lzq.course.server.dto.*;
import com.lzq.course.server.enums.CourseStatusEnum;
import com.lzq.course.server.service.CourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("webCourseCategory")
@RequestMapping("web/course")
public class CourseController {

    private final static Logger LOG = LoggerFactory.getLogger(CourseController.class);
    public static final String BUSINESS_NAME = "课程";

    @Resource
    private CourseService courseService;

    /**
     * 查询最新发布的三门课程
     * @param pageDto
     * @return
     */
    @GetMapping("/list-new")
    public ResponseDto listNew() {
        ResponseDto responseDto = new ResponseDto();
        PageDto pageDto = new PageDto();
        pageDto.setPage(1);
        pageDto.setSize(3);
        courseService.listNew(pageDto);
        responseDto.setContent(pageDto);

        return responseDto;
    }

    /**
     * web网站分页查询课程
     * @param pageDto
     * @return
     */
    @PostMapping("/list")
    public ResponseDto list(@RequestBody CoursePageDto coursePageDto) {
        ResponseDto responseDto = new ResponseDto();
        coursePageDto.setStatus(CourseStatusEnum.PUBLISH.getCode());
        courseService.list(coursePageDto);
        responseDto.setContent(coursePageDto);

        return responseDto;
    }

    @GetMapping("/find/{id}")
    public ResponseDto findCourse(@PathVariable String id) {
        LOG.info("查找课程开始：{}", id);
        ResponseDto responseDto = new ResponseDto();
        CourseDto courseDto = courseService.findCourse(id);
        responseDto.setContent(courseDto);
        LOG.info("查找课程结束：{}", responseDto);
        return responseDto;
    }
}
